home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / usr.bin / tty.c < prev    next >
C/C++ Source or Header  |  1996-11-30  |  3KB  |  134 lines

  1. This is a version of tty.c for linux.
  2.  
  3. john harvey    JOHNBOB at AUSVMQ    I don't speak for my employer.
  4. johnbob@innerdoor.austin.ibm.com    johnbob@there.austin.ibm.com
  5. johnbob@129.35.81.111               johnbob@129.35.81.200
  6.   main(int c,char**v){if(c==2){int n=atoi(v[1]);printf("%d\n",
  7.   n*main(-n+1,v));}else if(c<0)return-c*main(c+1,v);return 1;}
  8.  
  9. ---- Cut Here and unpack ----
  10. #!/bin/sh
  11. # This is a shell archive (shar 3.10)
  12. # made 01/21/1992 18:47 UTC by rjohnbobpts/4@AIX
  13. # Source directory /drive2/u/johnbob/net/linux/contrib
  14. #
  15. # existing files will NOT be overwritten
  16. #
  17. # This shar contains:
  18. # length  mode       name
  19. # ------ ---------- ------------------------------------------
  20. #    170 -rw-r--r-- Makefile
  21. #    158 -rw-r--r-- add.this
  22. #    587 -rw-r--r-- tty.c
  23. #
  24. touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
  25. if [ -s /tmp/s3_touch$$ ]
  26. then
  27.     TOUCH=can
  28. else
  29.     TOUCH=cannot
  30. fi
  31. rm -f /tmp/s3_touch$$
  32. # ============= Makefile ==============
  33. if test -f Makefile; then echo "File Makefile exists"; else
  34. echo "x - extracting Makefile (Text)"
  35. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  36. X#
  37. X#
  38. X
  39. XPROGRAM = tty
  40. XSRC    = tty.c
  41. XOBJS    = tty.o
  42. X
  43. XCC=cc
  44. XCFLAGS    = -O
  45. X
  46. X
  47. Xall: $(PROGRAM)
  48. X
  49. X$(PROGRAM): $(OBJS)
  50. X    $(CC) -o $(PROGRAM) $(OBJS) $(LIBS)
  51. X
  52. X.c.o:
  53. X    $(CC) $(CFLAGS) -c $<
  54. X
  55. SHAR_EOF
  56. chmod 0644 Makefile || echo "restore of Makefile fails"
  57. if [ $TOUCH = can ]
  58. then
  59.     touch -am 0120162992 Makefile
  60. fi
  61. fi
  62. # ============= add.this ==============
  63. if test -f add.this; then echo "File add.this exists"; else
  64. echo "x - extracting add.this (Text)"
  65. sed 's/^X//' << 'SHAR_EOF' > add.this &&
  66. XThe prototype for the ttyname() function wasn't in
  67. X/usr/include/unistd.h so you will have to add it to
  68. Xthe bottom of the file:
  69. X
  70. Xchar * ttyname(int fildes);
  71. X
  72. X
  73. SHAR_EOF
  74. chmod 0644 add.this || echo "restore of add.this fails"
  75. if [ $TOUCH = can ]
  76. then
  77.     touch -am 0120174392 add.this
  78. fi
  79. fi
  80. # ============= tty.c ==============
  81. if test -f tty.c; then echo "File tty.c exists"; else
  82. echo "x - extracting tty.c (Text)"
  83. sed 's/^X//' << 'SHAR_EOF' > tty.c &&
  84. X/*
  85. X    tty.c
  86. X    By John Harvey AKA johnbob AKA qk
  87. X    copy this all you want
  88. X*/
  89. X
  90. X#include <sys/types.h>
  91. X#include <stdio.h>
  92. X#include <unistd.h>
  93. X
  94. Xvoid syntax(int rv)
  95. X{
  96. X    fprintf(stderr,"syntax: tty [-s]\n");
  97. X    exit(rv);
  98. X}
  99. X
  100. Xmain(int argc, char **argv)
  101. X{
  102. X    int silent = 0;
  103. X    char *n;
  104. X
  105. X    if( argc == 2 )
  106. X    {
  107. X    if( strcmp(argv[1],"-s") )
  108. X        syntax(1);
  109. X    silent = 1;
  110. X    }
  111. X    else if ( argc != 1 )
  112. X    syntax(1);
  113. X    if( n=ttyname(0) )
  114. X    {
  115. X    if ( ! silent )
  116. X        printf("%s\n", n);
  117. X    exit(0);
  118. X    }
  119. X    else
  120. X    {
  121. X    if ( ! silent )
  122. X        printf("%s\n", "Not a tty");
  123. X    exit(1);
  124. X    }
  125. X}
  126. SHAR_EOF
  127. chmod 0644 tty.c || echo "restore of tty.c fails"
  128. if [ $TOUCH = can ]
  129. then
  130.     touch -am 0120173492 tty.c
  131. fi
  132. fi
  133. exit 0
  134.